package com.nanyang.tms.controller.company;

import javax.validation.Valid;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.nanyang.common.core.annotation.BindParam;
import com.nanyang.common.core.dict.CommonEnum;
import com.nanyang.common.core.domain.ApiResult;
import com.nanyang.common.core.exception.ServiceException;
import com.nanyang.common.core.page.PageBean;
import com.nanyang.tms.api.dto.request.companyadjustment.CompanyAdjustmentAddRequest;
import com.nanyang.tms.api.dto.request.companyadjustment.CompanyAdjustmentQueryRequest;
import com.nanyang.tms.api.dto.response.companyadjustment.CompanyAdjustmentResponse;
import com.nanyang.tms.api.service.companyadjustment.CompanyAdjustmentRpcService;

@RestController
@RequestMapping("/companyadjust")
public class CompanyAdjustmentController {

    @Reference(version = "1.0.0", timeout = 10000, check = false)
    private CompanyAdjustmentRpcService companyAdjustmentRpcService;

    /**
     * <p>listCompanyAdjustment</p>
     * <p>Description:查询列表</p>
     *
     * @param param
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ApiResult<PageBean<CompanyAdjustmentResponse>> listCompanyAdjustment(@RequestBody CompanyAdjustmentQueryRequest param) {
        ApiResult<PageBean<CompanyAdjustmentResponse>> apiResult = companyAdjustmentRpcService.listCompanyAdjustment(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }


    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @BindParam
    public ApiResult<Boolean> saveCompanyAdjustment(@BindParam @RequestBody @Valid CompanyAdjustmentAddRequest param) {
        ApiResult<Boolean> apiResult = companyAdjustmentRpcService.saveCompanyAdjustment(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
  

}
